<?php
class HotelresController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
	     //  echo "HS";
    }

    public function searchAction()
    {
    	
       Zend_Loader::loadFile('../application/default/forms/Hotelres.php');
		$Hotelresform = new Form_Hotelres();
        if ($this->getRequest()->isPost()) {
        	//print_r($_POST);
              $hotel_country=(int)($_POST['hotel_country']);
              $hotel_city=(int)($_POST['hotel_city']);
              $hotel_title=(int)($_POST['hotel_title']);
                                        
        }
         Zend_Loader::loadFile('../application/default/models/Hotelres.php');
         $hotellistmodel=new Hotelres();
         if($hotel_city ==0  && $hotel_country==0 && $hotel_title==0){
         	$this->_helper->redirector('index');
         }
         else{
         	
         	$hotellist=$hotellistmodel->gethotellist($hotel_country,$hotel_city,$hotel_title);
         }
        // print_r($hotellist);
         $this->view->hotellist = $hotellist;
            
    }

    public function editAction()
    {
    	$this->_helper->layout->setLayout('admin');	
        Zend_Loader::loadFile('../application/admin/forms/Hotel.php');
        $Hotel_form = new Form_Hotel();
        $this->view->form = $Hotel_form;
        
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($Hotel_form->isValid($formData)) {
                $hotel_id = (int)$Hotel_form->getValue('hotel_id');
                $hotel_title = $Hotel_form->getValue('hotel_title');
                $hotel_city = $Hotel_form->getValue('hotel_city');
                $hotel_country = $Hotel_form->getValue('hotel_country');
                $hotel_description = $Hotel_form->getValue('hotel_description');
                $hotel_contactperson = $Hotel_form->getValue('hotel_contactperson');
                $hotel_phone = $Hotel_form->getValue('hotel_phone');
                $hotel_fax = $Hotel_form->getValue('hotel_fax');
                $hotel_skype = $Hotel_form->getValue('hotel_skype');
                $is_Enabled=$Hotel_form->getValue('is_Enabled');
                Zend_Loader::loadFile('../application/admin/models/Hotel.php');
                $Hotel_model = new Hotel();
                $Hotel_model->updateHotel($hotel_id,$hotel_title, $hotel_city,$hotel_country,$hotel_description,$hotel_contactperson,$hotel_phone,$hotel_fax,$hotel_skype,$is_Enabled);
                
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
        	
            $hotel_id = $this->_getParam('hotel_id', 0);
            if ($hotel_id > 0) {
                Zend_Loader::loadFile('../application/admin/models/Hotel.php');
                $Hotel_model = new Hotel();
                $Hotel_form->populate($Hotel_model->getHotel($hotel_id));
            }
        }
        
    }

   /* public function deleteAction()
    {
      $this->_helper->layout->setLayout('admin');	
        if ($this->getRequest()->isPost()) {
            $del = $this->getRequest()->getPost('del');
            if ($del == 'Yes') {
               $hotel_id = $this->getRequest()->getPost('hotel_id');
                Zend_Loader::loadFile('../application/admin/models/Hotel.php');
                $Hotel_model = new Hotel();
                $Hotel_model->deleteHotel($hotel_id);
            }
            $this->_helper->redirector('index');
        } else {
            $hotel_id = $this->_getParam('hotel_id', 0);
            Zend_Loader::loadFile('../application/admin/models/Hotel.php');
            $Hotel_model = new Hotel();
            $this->view->hotel = $Hotel_model->getHotel($hotel_id);
       
        }
    }*/
    
         public function deleteAction()
          {
               $this->_helper->layout->setLayout('admin');	
               $hotel_id = $this->_getParam('hotel_id', 0);
           //    echo $hotel_id;exit;
                Zend_Loader::loadFile('../application/admin/models/Hotel.php');
                $Hotel_model = new Hotel();
                $Hotel_model->deleteHotel($hotel_id);
                 $this->_helper->redirector('index');
      
       
           }
    
			public function getcityAction(){
		  	        
		           $country=$_POST['country'];
		           $html="<option value='0'>Select City</option>";
		           Zend_Loader::loadFile('../application/default/models/common.php');
		           $commonmodel = new Common();
		           $cities=$commonmodel->getCity($country);
		           //print_r($cities);exit;
		           foreach ($cities as $city){
		           	$html .= '<option value="'.$city['cityid'].'">'.$city['city_name'].'</option>';
		           }
		         
		      echo $html ;exit;
		       
		    
		           
		  //echo json_encode($cities);
		          
		  }
		  
		public function gethotelbycountryAction(){
		  	        
		           $country=$_POST['country'];
		           $html1="<option value='0'>Select Hotel</option>";
		           Zend_Loader::loadFile('../application/default/models/common.php');
		           $commonmodel = new Common();
		           $hotels=$commonmodel->getHotelbyCountry($country);
		           //print_r($cities);exit;
		           foreach ($hotels as $hotel){
		           	$html1 .= '<option value="'.$hotel['hotel_id'].'">'.$hotel['hotel_title'].'</option>';
		           }
		         
		      echo $html1 ;exit;
		       
		    
		           
		  //echo json_encode($cities);
		          
		  }


}







